<script>
  import Socket from '@/util/socket'
	export default {
		onLaunch: function() {
			this.$u.vuex('vuex_deviceMode', "mobile_" + new Date().getTime());
			let plat = uni.getSystemInfoSync().platform;
			console.log("=============当前应用平台==============", plat);
			this.$u.vuex("vuex_OSPlat", plat);
      setTimeout(() => {
        this.getLatestVersion()
      }, 3500)
      if (this.vuex_token) {
        Socket.initWebScoket(this)
      }
		},
		onShow: function() {
      const nextUpdateTime = uni.getStorageSync('nextUpdateTime')
      if (nextUpdateTime && nextUpdateTime < Date.now()) {
        this.getLatestVersion()
      }
		},
		onHide: function() {
			console.log('App Hide')
		},
		onUnload: function() {
			this.trcApi.TRCLogout();
		},
		methods: {
      async getLatestVersion () {
        const sysInfo = uni.getSystemInfoSync()
        if (sysInfo.uniPlatform === 'web') return
        uni.setStorageSync('nextUpdateTime', Date.now() + (1000 * 60 * 10)) // 10分钟检查
        
        const oldVersion = sysInfo.appWgtVersion
        console.log('sysInfo:', sysInfo)
    
        const res = await this.$u.api.sys.getLatestVersion({
          os:  sysInfo.platform.toUpperCase()
        })
        if (res.code !== 200) return
        if (res.data.version === oldVersion) return
        const jump = uni.getStorageSync('version-jump')
        if (jump && jump === res.data.version) return
        uni.navigateTo({
          url: '/components/updateVersion/updateVersion?newVersion=' + JSON.stringify(res.data)
        })
      
        return true
      },
			getAppConfig: function() {
				let configData = {};
				this.$u.api.sys.getAppConfig({}).then(res => {
					//console.log("获取APP配置信息结果",res);
					if (res.code == 200) {
						let configArr = res.data;
						if (configArr && configArr.length > 0) {
							for (let i = 0; i < configArr.length; i++) {
								let config = configArr[i];
								let key = config.configKey;
								let value = config.configValue
								configData[key] = value;
							}
						}
						this.$u.vuex("vuex_app_config", configData);
						console.log("app配置信息", this.vuex_app_config);
					}
				})
			},
			listenTRC: function() {
				let that = this;
				that.trcApi.listenCallStatus({
					onError: function(res) {
						console.log(res);
					},
					onCallReceived: function(res) {
						console.log(res);
					},
					onCallCancelled: function(res) {
						console.log(res);
					},
					onCallBegin: function(res) {
						console.log(res);
					},
					onCallEnd: function(res) {
						console.log(res);
					},
				});
			}
		}
	}
</script>

<style lang="scss">
	/* 注意要写在第一行，同时给style标签加入lang="scss"属性 */
	@import "uview-ui/index.scss";

  .omit-1{
      overflow : hidden;
      text-overflow: ellipsis;
      display: -webkit-box;
      -webkit-line-clamp: 1;
      -webkit-box-orient: vertical;
    }

	.test-border {
		border: 1px solid red;
	}

	.u-font-famliy {
		font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
	}
</style>